﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ClientModel;

namespace Client
{
    /// <summary>
    /// Interaction logic for pagStartUp.xaml
    /// </summary>
    public partial class pagStartUp : Page
    {

        Service service = Service.getInstance();
        public pagStartUp()
        {
            InitializeComponent();

        }

        private void btnStartUp_Click(object sender, RoutedEventArgs e)
        {

            if (checkLicense())
            {
                try
                {
                    Service.getInstance().startSession();
                    MainWindow.SetPage(pagSession.getInstance());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }

        public bool checkLicense()
        {
            Boolean startup = false;
                if (service.isLicenseValid())
                {
                    startup = true;
                }
                else
                {
                    Service.getInstance().setLastConnectionDate(DateTime.Parse("1900/1/1"));
                    MessageBoxResult result = MessageBox.Show("Licens ikke godkendt. Kontakt leverandør eller forsøg igen.", "Licens Ikke Godkendt.", MessageBoxButton.OK, MessageBoxImage.Error);
                    startup = false;
                }
            return startup;
        }



    }
}
